﻿using ATTools.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.Environment.Extensions;

namespace ATTools.Drivers
{
    [OrchardFeature("ATTools.MicrosoftTranslatorWidget")]
    public class TranslationWidgetDriver : ContentPartDriver<TranslationWidgetPart> 
    {

        protected override DriverResult Display(TranslationWidgetPart part, string displayType, dynamic shapeHelper)
        {
            return ContentShape("Parts_TranslationWidget", () => shapeHelper.Parts_TranslationWidget(
                part
                ));
        }

        // GET
        protected override DriverResult Editor(TranslationWidgetPart part, dynamic shapeHelper)
        {
            return ContentShape("Parts_TranslationWidget_Edit",
                () => shapeHelper.EditorTemplate(
                    TemplateName: "Parts/TranslationWidget",
                    Model: part,
                    Prefix: Prefix));
        }

        // POST
        protected override DriverResult Editor(TranslationWidgetPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            updater.TryUpdateModel(part, Prefix, null, null);
            return Editor(part, shapeHelper);
        }
    }
}